package com.example.famhealing.schedule;

import com.example.famhealing.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class TopFragment extends Fragment{
	
	public static int state = 1;
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        // Inflate the layout for this fragment
		
		View view = inflater.inflate(R.layout.fragment_top, null);
		
		FragmentTransaction ft1 = getFragmentManager().beginTransaction();
        Fragment diaryFragment;
          
        diaryFragment = new DiaryFragment();
          
        ft1.replace(R.id.fragment_bottom, diaryFragment);
        ft1.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft1.commit();
		
		ImageButton diaryButton = (ImageButton) view.findViewById(R.id.diaryBtn);
	    ImageButton diagnoseButton = (ImageButton) view.findViewById(R.id.diagnoseBtn);
	    ImageButton meditationButton = (ImageButton) view.findViewById(R.id.meditationBtn);
	    
	    diaryButton.setOnClickListener(onBtnClickListener);
        diagnoseButton.setOnClickListener(onBtnClickListener);
        meditationButton.setOnClickListener(onBtnClickListener);
		
        return view;
    }
	
	 private OnClickListener onBtnClickListener = new OnClickListener()
	 {
		 @Override
	     public void onClick(View v)
		 {
			 switch(v.getId()) {
			 	case R.id.diaryBtn :
			 		
			 		state = 1;
			 		
			 		FragmentTransaction ft1 = getFragmentManager().beginTransaction();
			        Fragment diaryFragment;
			          
			        diaryFragment = new DiaryFragment();
			          
			        ft1.replace(R.id.fragment_bottom, diaryFragment);
			        ft1.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			        ft1.commit();
			 		
			 		break;
			 	case R.id.diagnoseBtn :
			 		
			 		state = 2;
			 		
			 		FragmentTransaction ft2 = getFragmentManager().beginTransaction();
			        Fragment diagnoseFragment;
			          
			        diagnoseFragment = new DiagnoseFragment();
			          
			        ft2.replace(R.id.fragment_bottom, diagnoseFragment);
			        ft2.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			        ft2.commit();
			 		
			 		break;
			 	case R.id.meditationBtn :
			 		
			 		state = 3;
			 		
			 		FragmentTransaction ft3 = getFragmentManager().beginTransaction();
			        Fragment meditationFragment;
			          
			        meditationFragment = new MeditationFragment();
			          
			        ft3.replace(R.id.fragment_bottom, meditationFragment);
			        ft3.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			        ft3.commit();
			 		
			 		break;	
			 	default:
			 		break;
			 }
	     }
	 };
	
}
